package leetcode_1_200;

import java.util.Stack;

public class LeeCode_20 {
    public static void main(String[] args) {

    }
    private static boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (stack.isEmpty()){
                stack.push(c);
            }else if (stack.peek() == '(' && c == ')'){
                stack.pop();
            } else if (stack.peek() == '[' && c == ']'){
                stack.pop();
            } else if (stack.peek() == '{' && c == '}'){
                stack.pop();
            }else {
                stack.push(c);
            }
        }
        return stack.isEmpty();
    }
}
